package com.zd.bms.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zd.bms.bean.vo.req.HardwareInfoListReqVo;
import com.zd.bms.service.IHardwareInfoService;
import com.zd.common.bean.model.HardwareInfo;
import com.zd.common.common.enums.StatusEnum;
import com.zd.common.common.utils.StringUtils;
import com.zd.common.dao.HardwareInfoDao;
import com.zd.common.dao.common.BaseDao;
import com.zd.common.dao.common.FindRequestEntity;
import com.zd.common.dao.common.OrderEnum;
import com.zd.common.dao.common.Page;
import com.zd.common.dao.common.WhereEnum;
import com.zd.common.service.impl.BaseServiceImpl;

@Service
public class HardwareInfoServiceImpl extends BaseServiceImpl<HardwareInfo> implements IHardwareInfoService {

	@Autowired
	private HardwareInfoDao hardwareInfo;

	@Override
	public BaseDao<HardwareInfo> getBaseDao() {
		return hardwareInfo;
	}

	@Override
	public Page<HardwareInfo> pageHardwareInfo(HardwareInfoListReqVo req) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		if (req.getScenicSpotId() != null && req.getScenicSpotId() != 0) {
			findReq.addWhere("scenic_spot_id", WhereEnum.EQ, req.getScenicSpotId());
		}
		if (!StringUtils.isBank(req.getName())) {
			findReq.addWhere("name", WhereEnum.LIKE, "%" + req.getName() + "%");
		}

		findReq.addWhere("status", WhereEnum.NE, StatusEnum.delete.getKey());
		if (req.getStatus() != null) {
			findReq.addWhere("status", WhereEnum.EQ, req.getStatus());
		}
		findReq.addOrder("create_time", OrderEnum.DESC);
		findReq.setPage(req.getPageNo(), req.getPageSize());
		Page<HardwareInfo> resultPage = page(findReq);
		return resultPage;
	}
}
